<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 堆内存 -->
    <script>
        let str = ''; //存放在栈内存
        let arr = [1, 2, 3]; //[1,2,3]存放在堆内存,var x和指针存放在栈内存
        let newArr = arr; //复制内存地址（指针）,与arr共同指向同一个内存空间

        // console.log(arr);//[1,2,3]
        // console.log(newArr);//[1,2,3]

        newArr[0] = 999; //更改了任意一个公用一个内存的变量内容
        console.log(arr); //[999,2,3]
        console.log(newArr); //[999,2,3]


        let obj = {
            id: 1
        }
        let newobj = obj;
        // console.log(obj);//{id: 1}
        // console.log(newobj);//{id: 1}
        newobj['name'] = 'lulu';
        console.log(obj); //{id: 1, name: "lulu"}
        console.log(newobj); //{id: 1, name: "lulu"}
    </script>
    <script>
        let str1 = 'No1';
        let str2 = str1;
        // console.log('我是str1 ' + str1);//我是str1 No1
        // console.log('我是str2 ' + str2);//我是str2 No1
        str2 = 'NO2';
        console.log('我是str1 ' + str1); //我是str1 No1
        console.log('我是str2 ' + str2); //我是str2 NO2
    </script>
</body>

</html>